home *** CD-ROM | disk | FTP | other *** search
/ Windows News 2010 Summer - Disc 1 / WN_Ete2010_CD1.iso / Onglet5 / Weezo / Weezo setup.exe / {code_appDir} / www / res / bookmarks / std / config.php next >
PHP Script  |  2010-05-19  |  13KB  |  312 lines

  1. <?php
  2. /**
  3.  * Standard bookmarks configuration file
  4.  *
  5.  * Configuration of standard bookmarks resource
  6.  * this script is included by /res/administration/std/resourceConfig.php
  7.  * this script should always be accessed through /res/administration/index.php including resourceConfig.php including this script
  8.  *
  9.  * resourceConfig.php sets 2 variables :
  10.  * $resourceData (array) which contains resource parameters
  11.  * $_ENV['configurationEnvironment'] which indicates if resourceConfig.php has been called from browser ('browser')
  12.  * or from application's embeded browser ('application')
  13.  *
  14.  * PHP version 5
  15.  *
  16.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  17.  * that is available through the world-wide-web at the following URI:
  18.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  19.  * the PHP License and are unable to obtain it through the web, please
  20.  * send a note to license@php.net so we can mail you a copy immediately.
  21.  *
  22.  * @category   NA
  23.  * @package    NA
  24.  * @author     Nicolas Bruley / Peer 2 World <contact@weezo.net>
  25.  * @copyright  2005-2009 Nicolas Bruley / Peer 2 World
  26.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  27.  * @version    CVS: $Id:$
  28.  * @link       http://www.weezo.net
  29.  * @since      File available since Release 1.0.0
  30.  */
  31.  
  32. require_once(INCLUDE_DIR.'bookmarkFunctions.php');
  33.  
  34. /**
  35.  * @desc function called when a data has been modified
  36.  *
  37.  * @param string $dataName : name of changed data
  38.  * @param mixed $previousDataValue : previous value
  39.  */
  40. function dataChanged($dataName, $previousDataValue){
  41.     global $resourceDataDir;
  42.     // If bookmarks type or path or size have changed, destroy all generated thumbnails
  43.     if($dataName=='bookmarksPath' || $dataName=='bookmarksType' || $dataName=='thumbnailMaxSize'){
  44.         if(file_exists($resourceDataDir) && is_dir($resourceDataDir)){$dir=$resourceDataDir;cfUnlinkDir($dir);mkdir($dir);}
  45.     }
  46. }
  47.  
  48.  
  49.  
  50. /*
  51.  ***************************************************************************************************************************
  52.  * Verify access rights
  53.  ***************************************************************************************************************************
  54.  */
  55. require_once(INCLUDE_DIR.'resourceConfigFunctions.php');
  56. rcConfigRights(false);
  57.  
  58. // Set PHP function that will be called on data change
  59. rcSetModifiedValuePHPFunction('dataChanged');
  60.  
  61. /**
  62.  * Async bookmark import
  63.  */
  64. if(isset($_POST['importBookmarks'])){
  65.     // Copy $resourceData into $_SESSION['res'][0] so functions using cfRgetVar / cfRSetVar can be used
  66.     rcCopyResourceDataToRVar();
  67.  
  68.     // Send async response
  69.     cfAsyncHeader();
  70.  
  71.     // Read custom bookmarks
  72.     readBookmarks('Custom');
  73.     $custom=cfRGetVar('bookmarks');
  74.     cfRSetVar('bookmarks',false);
  75.     $imported=false;
  76.  
  77.     // Import IE bookmarks
  78.     if($_POST['importBookmarks']=='IE')    {
  79.         $browserName=cfCaption('bookmarksIE');
  80.         // Set bookmarksPath to IE bookmarks path to override custom bookmarks path
  81.         cfRSetVar('bookmarksPath',browserBookmarksLocation('IE'));
  82.         // Import IE bookmarks
  83.         readBookmarks('IE');
  84.         $imported=cfRGetVar('bookmarks');
  85.     }
  86.  
  87.     // Import FF bookmarks
  88.     elseif($_POST['importBookmarks']=='FF')    {
  89.         $browserName=cfCaption('bookmarksFF');
  90.         // Set bookmarksPath to FF bookmarks path to override custom bookmarks path
  91.         cfRSetVar('bookmarksPath',browserBookmarksLocation('Firefox'));
  92.         // Import FF bookmarks
  93.         readBookmarks('Firefox');
  94.         $imported=cfRGetVar('bookmarks');
  95.     }
  96.  
  97.     // Import Opera bookmarks
  98.     elseif($_POST['importBookmarks']=='Opera')    {
  99.         $browserName=cfCaption('bookmarksOpera');
  100.         // Set bookmarksPath to Opera bookmarks path to override custom bookmarks path
  101.         cfRSetVar('bookmarksPath',browserBookmarksLocation('Opera'));
  102.         // Import Opera bookmarks
  103.         readBookmarks('Opera');
  104.         $imported=cfRGetVar('bookmarks');
  105.     }
  106.  
  107.     // Failed to import bookmarks
  108.     if(!$imported) echo cfAsyncXMLJSaction('alert("'.cfCaption('transfersFailed').'")');
  109.  
  110.     // Merge previous bookmark and imported bookmarks
  111.     $tail=array_pop($custom);
  112.     $nb=0; // Number of imported bookmarks
  113.     foreach ($imported as $key=>$value) if(isset($value['url'])){
  114.         $existing=false;
  115.         foreach ($custom as $key2=>$value2){
  116.             if($value2['type']=='b' && $value2['url']==$value['url']) {$existing=true;break;}
  117.         }
  118.         if(!$existing) {
  119.             $nb++;
  120.             $custom[]=$value;
  121.         }
  122.     }
  123.     $custom[]=$tail;
  124.  
  125.     // Generate custom bookmarks file
  126.     $output=''; $id=1;
  127.     foreach ($custom as $key=>$value) if(isset($value['url'])){
  128.         $output.="#URL\n    ID=".$id."\n    NAME=".cfUTF8Encode($value['name'])."\n    ";
  129.         if(isset($value['comments'])) $output.='DESCRIPTION='.cfUTF8Encode($value['comments'])."\n    ";
  130.         $output.='URL='.$value['url']."\n\n";
  131.         $id++;
  132.     }
  133.  
  134.     // Save file
  135.     if(file_put_contents(str_replace('*appDir*',cfAppRootDir(),$resourceData['bookmarksPath']).'/bookmarks.adr',$output))
  136.         echo cfAsyncXMLJSaction('alert("'.cfCaption('configImportOK',$browserName).' ('.$nb.')")');
  137.     else
  138.         echo cfAsyncXMLJSaction('alert("'.cfCaption('transfersFailed').'")');
  139.  
  140.     echo cfAsyncFooter();
  141.     exit;
  142. }
  143.  
  144.  
  145. /*
  146.  ***************************************************************************************************************************
  147.  * Display configuration form
  148.  ***************************************************************************************************************************
  149.  */
  150.  
  151. // Insert Javascript function needed for save button activation, and <form> with hidden fields.
  152. rcInsertScriptAndForm();
  153.  
  154. // Resource icon & name
  155. rcInsertIconName($resourceData);
  156.  
  157. // Bookmarks type (IE/Opera/Custom)
  158. echo '<div class="frame2">';
  159. echo '<div class="frame2Header">'.cfCaption('bookmarksType').'</div>';
  160. rcProcessData('bookmarksType',dataList,'Custom',array('IE','Opera','Firefox','Custom'),array(
  161. array(outIcon('iconIE.png'),'IE',cfCaption('bookmarksIE').'   '),
  162. array(outIcon('iconFF.png'),'Firefox',cfCaption('bookmarksFF').'  '),
  163. array(outIcon('iconOpera.png'),'Opera',cfCaption('bookmarksOpera').'<br><div class="frame3">'),
  164. array('<img src="'.rcResourceImage('iconCustom.png').'" style="margin-left:-10px;vertical-align:bottom">','Custom',cfCaption('bookmarksCustom').'')));
  165. echo '<b>'.cfCaption('genImport').cfCaption('genSeparator').'</b>';
  166. echo outButton('','javascript:importBookmarks(\'IE\')',outIcon('iconIE.png'),cfCaption('bookmarksIE'),false,'style="margin-right:3em"');
  167. echo outButton('','javascript:importBookmarks(\'FF\')',outIcon('iconFF.png'),cfCaption('bookmarksFF'),false,'style="margin-right:3em"');
  168. echo outButton('','javascript:importBookmarks(\'Opera\')',outIcon('iconOpera.png'),cfCaption('bookmarksOpera'));
  169. echo '</div>';
  170.  
  171. // Bookmarks path
  172. rcProcessData('bookmarksPath',dataFolderPath,cfAppDataRootDir().'/shared',false,cfCaption('bookmarksPath'));
  173. echo '</div>';
  174.  
  175. // Thumbnails
  176. echo '<div class="frame2">';
  177. echo '<div class="frame2Header">'.cfCaption('genThumbnails').'</div>';
  178. if(!$limitedConfig) echo outButton(cfCaption('genClear'),'javascript:clearThumbnails()',outIcon('eraser'),false,false,'style="float:right"');
  179. echo cfCaption('bookmarksDisplayThumbnails').'   ';
  180. rcProcessData('displayThumbnails',dataBoolean,true,false,array(cfCaption('genYes'),cfCaption('genNo')));
  181.  
  182. // Full-size thumbnails size
  183. rcProcessData('thumbnailSize',dataNumeric,640,false,false);
  184. rcProcessData('thumbnailJPGQuality',dataNumeric,60,false,false); // Thumbnails jpg quality
  185.  
  186.  
  187. // Thumbnails refresh rate
  188. rcProcessData('refreshRate',dataNumeric,15,array(0,999999),array(cfCaption('genRefreshRate'),2,cfCaption('genDays'))); // Thumbnails refresh rate
  189. echo '</div>';
  190.  
  191. // Thumbnails edition
  192. echo '<div class="frame2">';
  193. echo '<div class="frame2Header">'.cfCaption('bookmarksModificationAllowed').'</div>';
  194. rcProcessData('editAllowed',dataBoolean,true,false,array(cfCaption('genYes'),cfCaption('genNo')));
  195. rcProcessData('everybodyCanEdit',dataBoolean,true,false,array(cfCaption('bookmarksEverybodyCanEdit'),cfCaption('bookmarksAdministratorOnlyCanEdit')));
  196. echo '</div>';
  197.  
  198. rcProcessData('userTempDirAccessAllowed',dataBoolean,false,false,false/*do not display control*/); // Allow/forbid access to user temp directory (data/sessiondata/(session_id)/)
  199. rcProcessData('resourceDataDirAccessAllowed',dataBoolean,true,false,false/*do not display control*/); // Allow/forbid access to resource directory (data/res/(res type)/(res subType)/(res file name)/)
  200.  
  201. // Resource theme
  202. echo rcThemeSelectionControl();
  203.  
  204. // Save / cancel buttons
  205. echo '<br/>'.rcButtonSaveCancel();
  206.  
  207. // If resource need access to resource data dir, create it
  208. rcCreateResourceDataDir();
  209.  
  210. // Indicate that resource has been configured
  211. rcProcessData('resourceConfigured',dataBoolean,true,false,false/*do not display control*/);
  212.  
  213. // Save parameters
  214. rcWriteResourceFile($resourceData, $fileName);
  215.  
  216. // Enable / disable bookmarks edition by admin/everybody on "allow edition" button value
  217. ?>
  218. <script language="javascript" type="text/javascript">
  219. var prevType="<?php echo $resourceData['bookmarksType'];?>";
  220. var FF3=<?php if(file_exists(browserBookmarksLocation('Firefox').'/places.sqlite')) echo 1; else echo 0; ?>;
  221. <?php
  222.  
  223. // existing IE default bookmarks location ?
  224. echo 'var bookmarksPahtIEOK='.((browserBookmarksLocation('IE'))?'1':'0')."\n";
  225. // existing Firefox default bookmarks location ?
  226. echo 'var bookmarksPahtFFOK='.((browserBookmarksLocation('Firefox'))?'1':'0')."\n";
  227. // existing Opera default bookmarks location ?
  228. echo 'var bookmarksPahtOperaOK='.((browserBookmarksLocation('Opera'))?'1':'0')."\n";
  229. ?>
  230. function dataChanged(dataName,dataValue){
  231.     //alert(dataName+' '+dataValue);
  232.     if(dataName=="displayThumbnails"){
  233.         document.getElementsByName("refreshRate")[0].disabled=!dataValue;
  234.     }
  235.     if(dataName=="editAllowed"){
  236.         if(!dataValue) {
  237.             document.getElementsByName("everybodyCanEdit")[0].disabled=true;
  238.             document.getElementsByName("everybodyCanEdit")[1].disabled=true;
  239.         }
  240.         else{
  241.             document.getElementsByName("everybodyCanEdit")[0].disabled=false;
  242.             document.getElementsByName("everybodyCanEdit")[1].disabled=false;
  243.         }
  244.     }
  245.     else if(dataName=="bookmarksType" && dataValue!=prevType){
  246.         if(dataValue=="IE") {
  247.             dgn("bookmarksPath").value="<?php echo browserBookmarksLocation('IE',1);?>";
  248.             if(bookmarksPahtIEOK) dgn("bookmarksPath").style.color='';else  dgn("bookmarksPath").style.color='red';
  249.         }
  250.         if(dataValue=="Firefox") {
  251.             dgn("bookmarksPath").value="<?php echo browserBookmarksLocation('Firefox',1);?>";
  252.             if(bookmarksPahtFFOK) dgn("bookmarksPath").style.color='';else  dgn("bookmarksPath").style.color='red';
  253.             if(!FF3){
  254.                 document.getElementsByName("editAllowed")[0].disabled=true;
  255.                 document.getElementsByName("editAllowed")[1].disabled=true;
  256.                 document.getElementsByName("editAllowed")[1].checked=0;
  257.                 document.getElementsByName("editAllowed")[1].checked=1;
  258.                 document.getElementsByName("everybodyCanEdit")[0].disabled=true;
  259.                 document.getElementsByName("everybodyCanEdit")[1].disabled=true;
  260.             }
  261.         }
  262.         if(dataValue=="Opera") {
  263.             dgn("bookmarksPath").value="<?php echo browserBookmarksLocation('Opera',1);?>";
  264.             if(bookmarksPahtOperaOK) dgn("bookmarksPath").style.color='';else  dgn("bookmarksPath").style.color='red';
  265.         }
  266.         if(dataValue=="Custom") {
  267.             document.getElementsByName("bookmarksPath")[0].value="<?php echo browserBookmarksLocation('Custom');?>";
  268.  
  269.         }
  270.         if(dataValue!="Firefox"){
  271.             document.getElementsByName("editAllowed")[0].disabled=false;
  272.             document.getElementsByName("editAllowed")[1].disabled=false;
  273.             if(document.getElementsByName("editAllowed")[0].checked){
  274.                 document.getElementsByName("everybodyCanEdit")[0].disabled=false;
  275.                 document.getElementsByName("everybodyCanEdit")[1].disabled=false;
  276.             }
  277.             else{
  278.                 document.getElementsByName("everybodyCanEdit")[0].disabled=true;
  279.                 document.getElementsByName("everybodyCanEdit")[1].disabled=true;
  280.             }
  281.         }
  282.         prevType=dataValue;
  283.     }
  284.     if(dgn("bookmarksPath").style.color=='red') return false;
  285. }
  286. function importBookmarks(browser){
  287.     if(browser=='IE') if(!confirm("<?php echo cfCaption('genImport').cfCaption('genSeparator').'\\n'.cfCaption('bookmarksIE');?>")) return;
  288.     if(browser=='FF') if(!confirm("<?php echo cfCaption('genImport').cfCaption('genSeparator').'\\n'.cfCaption('bookmarksFF');?>")) return;
  289.     if(browser=='Opera') if(!confirm("<?php echo cfCaption('genImport').cfCaption('genSeparator').'\\n'.cfCaption('bookmarksOpera');?>")) return;
  290.     requestMethod="POST";
  291.     sendData("importBookmarks="+browser,undefined,true,3);
  292. }
  293.  
  294. function dataInitForm(){
  295. dataChangedNV("editAllowed");
  296. dataChanged("displayThumbnails");
  297. <?php
  298. if($resourceData["bookmarksType"]=='Firefox' && !file_exists($resourceData['bookmarksPath'].'/places.sqlite')){
  299. ?>
  300. document.getElementsByName("editAllowed")[0].disabled=true;
  301. document.getElementsByName("editAllowed")[1].disabled=true;
  302. document.getElementsByName("editAllowed")[1].checked=0;
  303. document.getElementsByName("editAllowed")[1].checked=1;
  304. document.getElementsByName("everybodyCanEdit")[0].disabled=true;
  305. document.getElementsByName("everybodyCanEdit")[1].disabled=true;
  306. <?php
  307. }
  308. ?>
  309. }
  310. function clearThumbnails(browser){maskShow(0,0); sendData("clearThumbnails=1",undefined,true,3);}
  311. dataInitForm();
  312. </script>